package com.heeexy.example.controller;

import com.alibaba.fastjson.JSONObject;
import com.heeexy.example.service.StatisticsService;
import com.heeexy.example.service.TokenService;
import com.heeexy.example.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
/**
 * @Author MyPC
 * @Date 2022/3/26 16:00
 * @description： 统计相关Controller
 * @Version 1.0
 */
@RestController
@RequestMapping("/census")
public class StatisticsController {

    private StatisticsService statisticsService;

    @Autowired
    private TokenService tokenService;

    @Autowired
    public void setStatisticsService(StatisticsService statisticsService) {
        this.statisticsService = statisticsService;
    }

    /**
     * 统计浏览人数
     * @return viewCount int
     */
    @GetMapping("/getViewCount")
    public JSONObject listArticle() {
        return statisticsService.viewsCount();
    }

    /**
     * 获取在线人数
     * @return long  UserOnlineNumber
     */
    @GetMapping("/getOnlineNumber")
    public  JSONObject getUserOnline(){
        System.out.println("CacheMapSize:"+tokenService.getCacheMapSize());
        return tokenService.getCacheMapSize();
    }
}
